<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *知识
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'项目列表'),
);
$return['project_status']=$this->project_status;
$return['check_status']=$this->check_status;
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>array(2,3));
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['cname'])){
		$params['cname like']='%'.trim($_RQ['cname']).'%';
		$return['params']['cname']=$_RQ['cname'];
	}
	if(!empty($_RQ['sn'])){
		$params['sn like']='%'.trim($_RQ['sn']).'%';
		$return['params']['sn']=$_RQ['sn'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_kexie_project',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$user=pdo_get('jy_kexie_project_cuser',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['user_id']));
			$member=pdo_get('core_members',array('id'=>$item['mid']),array('credit1','credit2','mobile','avatar','nickname','username','sex'));
			$item['member']=$member;
			$item['user']=$user;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'这里只显示待专家审核的项目，和刚审核的项目！','edit'=>false,'list'=>array(
			array('name'=>'sn','title'=>'项目编码','type'=>'string'),
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'user.cname','title'=>'公司名称','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'project_status'),
			array('name'=>'fa_starttime','title'=>'发售起始时间','type'=>'time'),
			array('name'=>'fa_edntime','title'=>'发售结束时间','type'=>'time'),
			array('name'=>'createtime','title'=>'申请时间','type'=>'time'),
		),'action' =>array(
			array('type'=>'modal','op'=>'check','title'=>'审批','show'=>array('status'=>array(2,8))),
			array('type'=>'href','op'=>'look','title'=>'查看'),
		)),
		'search'=>array(
			array('name'=>'sn','width'=>15,'title'=>'项目编码','type'=>'string'),
			array('name'=>'cname','width'=>15,'title'=>'公司名称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kexie_project',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));		
	}else{
		$item=array('type'=>$this->session('type'),'star'=>3);
	}
	$user=pdo_get('jy_kexie_project_cuser',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['user_id']));
	$item['user']=$user;
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回知识列表'),
		),
		'look'=>array(
			array('name'=>'sn','title'=>'项目编码','type'=>'string'),
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'baobiaofile','title'=>'申报表','type'=>'upfile'),
			array('name'=>'user.cname','title'=>'公司名称','type'=>'copy'),
			array('name'=>'user.username','title'=>'联系人','type'=>'copy'),
			array('name'=>'user.mobile','title'=>'联系电话','type'=>'copy'),
			array('name'=>'pid','title'=>'申报大项','type'=>'select','options'=>'groups'),
		)
	);
	$return['groups']=pdo_getall('jy_kexie_project_group',array('uniacid'=>$_SESSION['uniacid'],'pid'=>0),array('id','title'),'id');
	foreach($return['groups'] as &$gv){
		$gv['cids']=pdo_getall('jy_kexie_project_group',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$gv['id']),array('id','title'),'id');
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$status=intval($post['status']);
		if(!$status){
			exi('请选择审核通过还是不通过！','error');
		}
		pdo_update('jy_kexie_project',array('status'=>$status==1?3:8,'bb_remark'=>$post['bb_remark']),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('处理成功！','','list');
	}
	$item=$this->get('project',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定项目不存在！','error');
	}
	$item['status']=1;
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'审核报表',
		'edit'=>array(
			array('name'=>'baobiaofile','title'=>'申请报表','type'=>'upfile'),
			array('name'=>'status','title'=>'审核','type'=>'radio','options'=>'check_status'),
			array('name'=>'bb_remark','title'=>'不通过原因','type'=>'text','show'=>array('status'=>2)),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	exi('不能删除项目！','error');
}